package com.yatong.service.impl;

import com.yatong.entity.TrackRecord;
import com.yatong.dao.TrackRecordDao;
import com.yatong.service.TrackRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (TrackRecord)表服务实现类
 *
 * @author makejava
 * @since 2018-10-31 09:01:39
 */
@Service("trackRecordService")
public class TrackRecordServiceImpl implements TrackRecordService {
    @Resource
    private TrackRecordDao trackRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TrackRecord queryById(Integer id) {
        return this.trackRecordDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<TrackRecord> queryAllByLimit(int offset, int limit) {
        return this.trackRecordDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param trackRecord 实例对象
     * @return 实例对象
     */
    @Override
    public TrackRecord insert(TrackRecord trackRecord) {
        trackRecord.setAddTime(new Date());

        trackRecord.setUserId(1);
        trackRecord.setUserName("颜文字君");
        trackRecord.setUserImg("../img/a1.jpg");

        trackRecord.setCoordinationId(2);
        trackRecord.setCoordinationImg("../img/a5.jpg");

        this.trackRecordDao.insert(trackRecord);
        return trackRecord;
    }

    /**
     * 修改数据
     *
     * @param trackRecord 实例对象
     * @return 实例对象
     */
    @Override
    public TrackRecord update(TrackRecord trackRecord) {
        this.trackRecordDao.update(trackRecord);
        return this.queryById(trackRecord.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.trackRecordDao.deleteById(id) > 0;
    }


    /**
     * 筛选条件查询多条数据
     *
     * @param id
     * @return
     */
    public List<TrackRecord> queryAll(String id){
        TrackRecord trackRecord = new TrackRecord();
        trackRecord.setCompanyId(Integer.parseInt(id));
        List<TrackRecord> trackRecords = this.trackRecordDao.queryAll(trackRecord);
        return trackRecords;
    }
}